<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<html>
	<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		<title>盘库确认-金融风险管理系统</title>
		<script src="${contextPath}/scripts/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/json/json2.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/common.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/scriptvalidator.js" type="text/javascript"></script>
		<link href="${contextPath}/styles/default.css" rel="stylesheet" type="text/css" />
		<script language='javascript'>
		//顶部按钮
		function checkAll(s){
			if(s=='ck00'){
				$("[type=checkbox][name='ck00']").attr('checked', true);	
				$("[type=checkbox][name='ck01']").attr('checked', false);	
			}else if(s=='ck01'){
				$("[type=checkbox][name='ck00']").attr('checked', false);	
				$("[type=checkbox][name='ck01']").attr('checked', true);
			}else if(s=='ck10'){
				$("[type=checkbox][name='ck10']").attr('checked', true);	
				$("[type=checkbox][name='ck11']").attr('checked', false);
				$("[type=checkbox][name='ck12']").attr('checked', false);
			}else if(s=='ck11'){
				$("[type=checkbox][name='ck10']").attr('checked', false);	
				$("[type=checkbox][name='ck12']").attr('checked', false);
				$("[type=checkbox][name='ck11']").attr('checked', true);
			}else if(s=='ck12'){
				$("[type=checkbox][name='ck10']").attr('checked', false);	
				$("[type=checkbox][name='ck11']").attr('checked', false);
				$("[type=checkbox][name='ck12']").attr('checked', true);
			}
			
		}
		
		//全部在库、全部不在库
		function changeAll(i){
			var data=$("#allData").val();
			var dataObj=eval("("+data+")");//转换为json对象 
			if(i=='1'){
				checkAll("ck00");
				checkAll("ck10");
			}else{
				checkAll("ck01");
				checkAll("ck11");
			}
			$.each(dataObj,function(idx,item){
				item.ck00=i;
				item.ck10=i;
			}); 
			$("#allData").val(JSON.stringify(dataObj));
		}
		
		//跳页
		function jumpPage(page) {
			build("allData");
			var form1 = document.form1;
			form1.action = "<s:property value='contextPath'/>/cs/jumpPage.do?currentPage=" + page;
			form1.submit();
		}
		
		//提交后台前构建json数组
		function build(id_){
			var rus=$("#allData").val();
			var rusObj=eval("("+rus+")");
			
			var ck00s=$("[name='ck00']");
			var ck01s=$("[name='ck01']");
			var ck10s=$("[name='ck10']");
			var ck11s=$("[name='ck11']");
			var ck12s=$("[name='ck12']");
			var msgs=$("[name='msg']");
			ck00s.each(function(i){ 
				var tmp={};
				tmp['id']=ck00s[i].value;
				if(ck00s[i].checked){
					tmp['ck00']='1';	
				}else if(ck01s[i].checked){
					tmp['ck00']='0';
				}else{
					tmp['ck00']='-1';
					//alert("本页还有未确认的数据");
					//return ;
				}
				
				if(ck10s[i].checked){
					tmp['ck10']='1';	
				}else if(ck11s[i].checked){
					tmp['ck10']='0';
				}else if(ck12s[i].checked){
					tmp['ck10']='2';
				}else{
					tmp['ck10']='-1';
					//alert("本页还有未确认的数据");
					//return ;
				}
				tmp['msg']=msgs[i].value;;
				rusObj.push(tmp);
			});
			//$("#txa").val(JSON.stringify(rusObj));
			$("#"+id_).val(JSON.stringify(rusObj));
			//alert($("#"+id_).val());
		}
		
		//提交前检查是否有未确认的合格证
		function check_(){
			build("tmpData");
			var data=$("#tmpData").val();
			var dataObj=eval("("+data+")");//转换为json对象 
			var flag=true;
			$.each(dataObj,function(idx,item){
				//alert(item.ck00);
				if(item.ck00=='-1'||item.ck10=='-1'){
					flag=false;
					return false;
				}
			}); 
			if(flag)
				$("#allData").val(data);
			return flag;
		}
		
	  $(document).ready(function(){
		  //重新盘库、提交、暂存
			$("[type=button][name='btn_submit']").click(function(e){
				var op=e.target.id;
				var form1 = document.form1;
				if(op=='save'){
					build("allData");
					form1.action ="<s:property value='contextPath'/>/cs/save.do?currentPage=${currentPage}";
				}else if(op=='confirm'){
					if(check_()){
						form1.action ="<s:property value='contextPath'/>/cs/confirm.do";
					}else{
						alert("还有未确认在库状态的合格证,暂不能执行此操作");
						return false;
					}
					
				}else{
					if(confirm("重新盘库将会清空所有在库状态和备注,确定？")){
						form1.action ="<s:property value='contextPath'/>/cs/reset.do";		
					}else{
						return false;
					}
				}
				form1.submit();
			}); 
			
		  //反选
			$("[type=checkbox]").click(function(e){
				if(e.target.checked){
					var eid=e.target.id;
					var e1,e2;
					if(eid.indexOf("0_")>0){
						e1=eid.replace("0_","1_");
						e2=eid.replace("0_","2_");
					}else if(eid.indexOf("1_")>0){
						e1=eid.replace("1_","0_");
						e2=eid.replace("1_","2_");
					}else if(eid.indexOf("2_")>0){
						e1=eid.replace("2_","0_");
						e2=eid.replace("2_","1_");
					}
					if($("#"+e1))
						$("#"+e1).attr('checked', false);
					if($("#"+e2))
						$("#"+e2).attr('checked', false);
				}
			});
			
			//初始化
			var data=$("#initData").val();
			var dataObj=eval("("+data+")");//转换为json对象 
			$.each(dataObj,function(idx,item){
				if(item.ck00=='1'){
					$("#ck00_"+item.id).attr('checked',true);
					$("#ck01_"+item.id).attr('checked',false);
				}else if(item.ck00=='0'){
					$("#ck00_"+item.id).attr('checked',false);
					$("#ck01_"+item.id).attr('checked',true);
				}
				
				if(item.ck10=='1'){
					$("#ck10_"+item.id).attr('checked',true);
					$("#ck11_"+item.id).attr('checked',false);
				}else if(item.ck10=='0'){
					$("#ck10_"+item.id).attr('checked',false);
					$("#ck11_"+item.id).attr('checked',true);
				}else if(item.ck10=='2'){
					$("#ck10_"+item.id).attr('checked',false);
					$("#ck11_"+item.id).attr('checked',false);
					$("#ck12_"+item.id).attr('checked',true);
				}
				if(item.msg!=null&&item.msg!=''&&item.msg!='null')
					$("#msg_"+item.id).val(item.msg);
			}); 
			});
	  function del(e,id){
			if(confirm("附件操作不可恢复,确认删除吗?")){
				var f=false;
				$.ajax({
					  async:false,
					  type: 'POST',
					  url: "<s:property value='contextPath'/>/attach/del.do?id="+id,
					  dataType: "json",
					  success: function(data) {
							  	f = data.flag;
							  	if(f){
							  		//alert("删除成功");
							  		$(e).parent().remove();
							  	}
							}		
						,
						error:function(data){
						}
					}); 
				
			}
			
		}
	  
	  function exportStore(){
			var form1 = document.form1;
			form1.action = "<s:property value='contextPath'/>/cs/exportStore.do";
			form1.submit();
		}
		</script>
	</head>
	<body  leftmargin='8' topmargin='8'>
	<div class="navigation">
	    <span><a href="javascript:window.history.back();"><img src="${contextPath}/images/back_nav_btn.png" /></a>
	    <a href="javascript:window.history.back();">返回</a>
	    <a href="javascript:window.history.forward();"><img src="${contextPath}/images/go_nav_btn.png" /></a>
	     <a href="javascript:window.history.forward();">前进</a>
	    <a href="javascript:window.location.reload();"><img src="${contextPath}/images/refresh_nav_btn.png" /></a>
	     <a href="javascript:window.location.reload();">刷新</a>
	    </span>盘库管理&gt;&gt;盘库&gt;&gt;确认
  	</div>
  	<form id="form1" name="form1" action="jumpPage.do" method="post" enctype="multipart/form-data">
  	<div class="xt_main_right_center">
  		<table width="100%" border="0" cellpadding="1" cellspacing="1">
			<tr>
				<td class="left-td-width-bg">
					区域经理：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.areaManager.realName"/>
				</td>
				<td class="left-td-width-bg">
					店号：
				</td>
				<td  class="bline" align="left">
					<s:property value="entity.shop.shopMark"/>
				</td>
				<td class="left-td-width-bg">
					驻店顾问：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.shopUser.realName"/>
				</td>
			</tr>
			<tr>
				<td class="left-td-width-bg">
					应在库合格证：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.options.size"/>
				</td>
				<td class="left-td-width-bg">
					应在库车：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.options.size"/>
				</td>
				<td class="left-td-width-bg">
					店名：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.shop.shopName"/>
				</td>
			</tr>
			<tr>
				<td class="left-td-width-bg">
					盘库方式：
				</td>
				<td class="bline" align="left">
					<%-- <s:if test="entity.live">现场</s:if><s:else>非现场</s:else> --%>
					<input type="radio" name="entity.live" <s:if test="entity.live">checked="checked"</s:if> value="true">现场 &nbsp;&nbsp;
					<input type="radio" name="entity.live" <s:if test="!(entity.live)">checked="checked"</s:if> value="false">非现场
				</td>
				<td class="left-td-width-bg">
					盘库来源：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.source.name"/>
				</td>
				<td class="left-td-width-bg">
					发起人：
				</td>
				<td class="bline" align="left">
					<s:property value="entity.sponsor.realName"/>
				</td>
			</tr>
		</table>
  	</div>
  	<br/>


	<table width="90%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
	  <td>
	    	渠道:
	    	<%-- <input name="option.certification.brand.name" class="input" style="width: 120px" value="<s:property value='option.certification.brand.name'/>" /> --%>
	    	<select  class="input" name="option.certification.brand.name" id="select2" style="width: 120px">
		       		<option  value="">****请选择****</option>
			         <s:iterator value="brandList" status="i" id="b">
			          <option <s:if test='option.certification.brand.name==#b.name'>selected="selected"</s:if>  value="${b.name }">${b.name }</option>
			          </s:iterator>
		      </select>
	    	金融机构:
	    	<%-- <input name="option.certification.financial.name" class="input" style="width: 120px" value="<s:property value='option.certification.financial.name'/>" /> --%>
	    	<select  class="input" name="option.certification.financial.name" id="select2" style="width: 120px">
		        <option  value="">****请选择****</option>
		         <s:iterator value="fiList" status="i" id="b">
		          <option <s:if test='option.certification.financial.name==#b.name'>selected="selected"</s:if>  value="${b.name }">${b.name }</option>
		          </s:iterator>
		      </select>
		      
	    	合格证号:<input name="option.certification.certificationNum" class="input" style="width: 120px" value="<s:property value='option.certification.certificationNum'/>" />
	    	车架号:<input name="option.certification.chassis" class="input" style="width: 120px" value="<s:property value='option.certification.chassis'/>" />
	    	<input type="button"  value="" onclick="jumpPage(1)"  class="btn_query"/>
	    </td>
	    <td align="right"><a href="javascript:exportStore();"><img src="${contextPath}/images/export.png" alt="导出"  /></a></td>
	  </tr>
	</table> 
	<!-- 库存清单开始 -->	
	<s:if test="page!=null&&page.result!=null">
		<!--
		<br/> 
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
		  <tr>
		    <td height="25" align="left"><font color="#0066CC"><strong>库存清单：</strong></font></td>
		    <td height="25" align="right">
		    </td>
		  </tr>
		</table>  -->
		<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
		  <tr> 
		    <td width="3%" class="top-td-width-bg">序号</td>
		    <td width="6%" class="top-td-width-bg">渠道</td>
		    <td width="7%" class="top-td-width-bg">金融机构</td>
		    <td width="7%" class="top-td-width-bg">合格证号</td>
		    <td width="7%" class="top-td-width-bg">车架号</td>
		    <td width="7%" class="top-td-width-bg">发动机号</td>
		    <td width="7%" class="top-td-width-bg">车型</td>
		    <td width="6%" class="top-td-width-bg">单价</td>
		    <td width="7%" class="top-td-width-bg">入库日期</td>
		    <td width="5%" class="top-td-width-bg">状态</td>
		    <td width="7%" class="top-td-width-bg">二库地址</td>
		    <td width="11%" class="top-td-width-bg">合格证现状<br/><input type="button" onclick="checkAll('ck00')" value="在库"/>&nbsp;<input type="button" onclick="checkAll('ck01')"  value="不在库"/></td>
		    <td width="11%" class="top-td-width-bg">车辆现状<br/><input type="button"  onclick="checkAll('ck10')" value="在库"/>&nbsp;<input type="button" onclick="checkAll('ck11')"  value="不在库"/>&nbsp;<input type="button" onclick="checkAll('ck12')"  value="不管车"/></td>
		    <td width="9%" class="top-td-width-bg">备注</td>
		  </tr>
		 <s:iterator value="page.result" status="stx" >
			<tr height="26" align="center" bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor='#FCFDEE';" onmouseout="javascript:this.bgColor='#FFFFFF';"> 
			 	<td align="center"><s:property value="#stx.index+1"/></td>
			    <td align="center"><s:property value="certification.brand.name"/></td>
			    <td align="center"><s:property value="certification.financial.name"/></td>
			    <td align="center"><s:property value="certification.certificationNum"/></td>
			    <td align="center"><s:property value="certification.chassis"/></td>
			    <td align="center"><s:property value="certification.engine"/></td>
			    <td align="center"><s:property value="certification.motorcycleType"/></td>
			    <td align="right"><s:property value="formatAmount(certification.supplyPrice)"/></td>
			    <td align="center"><s:date name="certification.warehouseDate" format="yyyy-MM-dd" /></td>
			    <td align="center"><s:if test="certification.theAddress!=null&&certification.state.index==2">在库(二网)</s:if><s:else><s:property value="certification.state.name" /></s:else></td>
		    	<td align="center"><s:property value="certification.theAddress"/></td>
			    <td align="center"><input id="ck00_<s:property value='id'/>" name="ck00" value="<s:property value='id'/>" type="checkbox" />在库&nbsp;<input id="ck01_<s:property value='id'/>"  name="ck01" type="checkbox" />不在库</td>
			    <td align="center"><input id="ck10_<s:property value='id'/>"  name="ck10" type="checkbox" />在库&nbsp;<input id="ck11_<s:property value='id'/>"  name="ck11" type="checkbox" />不在库&nbsp;<input id="ck12_<s:property value='id'/>"  name="ck12" type="checkbox" />不管车</td>
			    <td align="center"><input id="msg_<s:property value='id'/>" name="msg" /></td><%-- <s:if test="entity.status.index!=1">readonly="readonly"</s:if> --%>
			</tr>
		</s:iterator>
		<tr bgcolor="#F9FCEF"> 
		 <td height="36" colspan="14" align="center">
				<%@ include file="/WEB-INF/view/common/pagination.jsp"%>
		 </td>
		</tr>
		</table>
	</s:if>
	
	<table width="90%" border="0" cellpadding="0" cellspacing="0"  style="border-color:#CCCCCC;">
		 <tr>
	          <td class="left-td-width-bg">备注：</td>
	          <td>
	          		<textarea id="txa" rows="4" cols="40"  class="input_textarea_width60" name="entity.remark"   dataType="Require" msg="审核意见不能为空"><s:property value="entity.remark"/></textarea>
	          		
	          </td>
	          <td style="padding-left: 0px;" align="left" valign="top"><input type="button" onclick="changeAll(1)" value="全部在库" />&nbsp;<input type="button" onclick="changeAll(0)" value="全部不在库" /></td>
	    </tr>
	   <%--  <s:if test="entity.status.index==1||entity.status.index==2"> --%>
			 <tr>
		          <td class="left-td-width-bg">附件：</td>
		          <td colspan="2">
		          	<input name="file"  type="file" id="file" size="16" style="width: 200px" />
					<s:iterator value="attachs" >
					<div style="display: inline">
						<a href="${contextPath}/attach/download.do?id=<s:property value="id"/>" ><s:property value="name"/></a>&nbsp;<img name="img_del" id="<s:property value="id"/>" src="${contextPath}/images/del.gif" alt="删除" width="16" height="18" border="0" onclick="javascript:del(this,<s:property value="id"/>)" />
					</div>
					</s:iterator> 
				  </td>
		    </tr>
	    <%-- </s:if> --%>
	    <tr style="padding-top: 20px">
			<td class="bline" colspan="3" align="center">
	          	<input type="button" name="btn_submit" id="again" value='重新盘库' />&nbsp;&nbsp;
	          	<input type="button" name="btn_submit" id="confirm" value='确认' />&nbsp;&nbsp;
	          	<input type="button" name="btn_submit" id="save" value='暂存' />&nbsp;&nbsp;
          </td>
	    </tr>
	</table>
	
	<input type="hidden" id="initData" name="initData" value="<s:property value='pageData'/>"/>
	<input type="hidden" id="allData" name="allData" value="<s:property value='allData'/>"/>
	<input type="hidden" name="redirectUrl" value='<s:property value='redirectUrl'/>'/>
	<input type="hidden" name="entity.id" value='<s:property value='entity.id'/>'/>
	<input type="hidden" id="tmpData" />
	</form>
	</body>
</html>